home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / maestro / source / cdedit / messages.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-15  |  8.8 KB  |  295 lines

  1. /*
  2.  * Copyright (c) 1990, 1991 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software and 
  5.  * its documentation for any purpose is hereby granted without fee, provided
  6.  * that (i) the above copyright notices and this permission notice appear in
  7.  * all copies of the software and related documentation, and (ii) the name
  8.  * Stanford may not be used in any advertising or publicity relating to
  9.  * the software without the specific, prior written permission of
  10.  * Stanford.
  11.  * 
  12.  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, 
  13.  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY 
  14.  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  
  15.  *
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INCIDENTAL,
  17.  * INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES
  18.  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER OR NOT
  19.  * ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY,
  20.  * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  21.  * SOFTWARE.
  22.  */
  23.  
  24. /* $Header: /Source/Media/collab/cdEdit/RCS/messages.c,v 2.12 92/05/29 12:37:50 drapeau Exp $ */
  25. /* $Log:    messages.c,v $
  26.  * Revision 2.12  92/05/29  12:37:50  drapeau
  27.  * Modified code to track new name of the MAEstro "Selection" structure;
  28.  * it is now named "MAESelection".
  29.  * 
  30.  * Revision 2.11  92/05/14  16:40:19  drapeau
  31.  * Minor change in GetAppIcon() to reflect new location of the program icon.
  32.  * 
  33.  * Revision 2.10  92/01/03  17:50:40  drapeau
  34.  * Changed all calls to Browse() to use "0" instead of "NULL", taking into
  35.  * account the ANSI-C definition of NULL as (void*)0.
  36.  * 
  37.  * Revision 2.0  91/10/06  21:01:43  chua
  38.  * Update to version 2.0
  39.  * 
  40.  * Revision 1.74  91/09/24  16:31:34  chua
  41.  * In GetSelection, obtain the duration and label from the duration and label arrays,
  42.  * instead of from the text fields in the edit panel.
  43.  * 
  44.  * Revision 1.73  91/09/18  17:26:55  chua
  45.  * Removed the hard path for the include files.
  46.  * 
  47.  * Revision 1.72  91/09/16  14:21:28  chua
  48.  * In OpenDoc, do not set cdfilename to the filename passed yet.  This will be done in the
  49.  * OpenHandler if there are no errors in opening the file.
  50.  * 
  51.  * Revision 1.71  91/09/03  15:15:35  chua
  52.  * Added the copyright header.
  53.  * 
  54.  * In OpenDoc, it is no longer necessary to check if the filename is "untitled", since
  55.  * the TimeLine will not pass this value back.
  56.  * 
  57.  * In GetDoc, simply return the name of the current file been edited (there is a variable,
  58.  * cdfilename, which keeps track of this filename).
  59.  * 
  60.  * Added a new function, GetAppIcon, which will return the icon bits of the cdEdit icon
  61.  * to the calling application.
  62.  * 
  63.  * Revision 1.7  91/08/19  19:22:47  chua
  64.  * In GetSelection, set duration = -1 if there is no currently selected edit.
  65.  * 
  66.  * Revision 1.6  91/08/19  14:53:37  chua
  67.  * Made a change in GetSelection to make sure that select.start = -1 if
  68.  * there is no edit selected.
  69.  * 
  70.  * Revision 1.5  91/08/19  14:37:14  chua
  71.  * In GetDoc, return 'untitled' if there is no filename specified.
  72.  * Apparently, the network does not accept NULL as a return value.
  73.  * 
  74.  * In GetSelection, return selection.start = -1 if there is no selection
  75.  * specified.
  76.  * 
  77.  * Revision 1.4  91/08/19  13:59:46  chua
  78.  * In GetDoc, return NULL if there is no filename specified.
  79.  * In GetSelection, return NULL if there is no selection specified.
  80.  * 
  81.  * Revision 1.3  91/08/13  17:43:59  chua
  82.  * In SetSelection, perform a seek to the desired place.
  83.  * 
  84.  * Revision 1.2  91/07/11  18:31:17  chua
  85.  * In the SetSelection function, only perform if the selection received has
  86.  * a start value > 0.  Also introduced a new variable, perform, which is
  87.  * set to 1 if a valid selection is received.  Only if perform = 1 will 
  88.  * PerformSelection actually do its job.
  89.  * 
  90.  * Revision 1.1  91/07/09  16:47:46  chua
  91.  * 
  92.  * 
  93.  * Revision 1.0  91/07/08  13:46:11  chua
  94.  * Initial revision
  95.  *  */
  96.  
  97. static char messagesrcsid[] = "$Header: /Source/Media/collab/cdEdit/RCS/messages.c,v 2.12 92/05/29 12:37:50 drapeau Exp $";
  98.  
  99. #include "main.h"
  100. #include <Browse.h>
  101.  
  102. static int perform;                            /* To indicate if PerformSelection is to be executed. */
  103.  
  104. /* 
  105.  * Opens the edit list stored in the filename parameter.
  106.  */
  107. void OpenDoc(filename)
  108.      char **filename;
  109. {
  110.   int result;
  111.  
  112.   if (strcmp(cdfilename, *filename) != 0)                /* Check if the filename is the same as the currently existing file */
  113.   {
  114.     result = CheckChanges(LoadFile);                    /* Check if there are unsaved changes */
  115.     if (result == NOTICE_NO)                        /* Proceed to load the file */
  116.     {
  117.       change = 0;
  118.       Browse(*filename, BrowseCheckOpen, 0, "#CD Edit Document#", "cdEdit");
  119.     }
  120.   }
  121. }
  122.  
  123. /* 
  124.  * Sets the current selection on the edit panel 
  125.  */
  126. void SetSelection(MAESelection* selection)
  127. {
  128.   Msf absoluteStart;
  129.   struct cdrom_msf msf;
  130.   char buf[80];
  131.   
  132.   perform = 0;
  133.   if (selection->start > 0 && selection->start <= lines)        /* Check that such a selection exist */
  134.   {
  135.     perform = 1;
  136.     if (editnum != -1)                            /* Deselect any current selection */
  137.     {
  138.       xv_set(cdEdit_EditPopup->EditList,
  139.          PANEL_LIST_SELECT, editnum, FALSE,
  140.          NULL);
  141.     }
  142.     editnum = selection->start - 1;
  143.     LoadStartEnd();                            /* Load the start and end times on the current selection textfields */
  144.     sprintf(buf, "%d", (duration[editnum] + 500) / 1000);
  145.     xv_set(cdEdit_EditPopup->EditPopupDurationText, PANEL_VALUE, buf, NULL); /* Display the duration in the duration textfield */
  146.     absoluteStart = (Msf) GetCurrentStart();
  147.     if (selection->offset > 0)                        /* Check if there is any offset (play partial selection */
  148.     {
  149.       absoluteStart->frame += selection->offset * 75 / 1000;        /* Calculate the new start time in msf */
  150.       while (absoluteStart->frame >= 75) 
  151.       {
  152.     absoluteStart->sec ++;
  153.     absoluteStart->frame -= 75;
  154.       }
  155.       while (absoluteStart->sec >= 60) 
  156.       {
  157.     absoluteStart->min ++;
  158.     absoluteStart->sec -= 60;
  159.       }
  160.       offsetStart = absoluteStart;
  161.       offset = 1;
  162.     }
  163.     if (absoluteStart == NULL) 
  164.     {
  165.       return;
  166.     }
  167.     SetDuration(-1);                            /* Display the duration of the current selection */
  168.     xv_set(cdEdit_EditPopup->EditList,                    /* Select the entry to be played */
  169.        PANEL_LIST_SELECT, editnum, TRUE,
  170.        NULL);
  171.     msf.cdmsf_min0 = absoluteStart->min;
  172.     msf.cdmsf_sec0 = absoluteStart->sec;
  173.     msf.cdmsf_frame0 = absoluteStart->frame;
  174.     msf.cdmsf_min1 = absoluteStart->min;
  175.     msf.cdmsf_sec1 = absoluteStart->sec;
  176.     msf.cdmsf_frame1 = absoluteStart->frame;
  177.     playerState = PlayMode;
  178.     cdrom_play_msf(fd, msf);
  179.   }
  180. }
  181.  
  182. /* 
  183.  * Play the current selection 
  184.  */
  185. void PerformSelection()
  186. {
  187.   if (editnum != -1 && perform == 1) 
  188.   {
  189.     PreviewStartEnd(NULL, NULL);
  190.   }
  191. }
  192.  
  193. /* 
  194.  * Return the current filename.
  195.  */
  196. char** GetDoc(unusedArg)
  197.      void *unusedArg;
  198. {
  199.   return (&cdfilename);
  200. }
  201.  
  202. /* 
  203.  * Get the current selection number 
  204.  */
  205. MAESelection* GetSelection(unusedArg)
  206.      void *unusedArg;
  207. {
  208.   static MAESelection select;
  209.  
  210.   select.duration = -1;
  211.   if (editnum >= 0) 
  212.   {
  213.     select.duration = duration[editnum];
  214.     select.start = editnum + 1;
  215.     select.end = editnum + 1;
  216.     select.offset = 0;
  217.     strcpy(select.label, label[editnum]);
  218.   }
  219.   return (&select);
  220. }
  221.  
  222. /*
  223.  * Halt play.  A stop message is sent to the CD player to halt it.
  224.  */
  225. void HaltSelection()
  226. {
  227.   Stop(NULL, NULL);  
  228. }
  229.  
  230. /*
  231.  * Pause play.
  232.  */
  233. void PauseSelection()
  234. {
  235.   Pause(NULL, NULL);
  236. }
  237.  
  238. /*
  239.  * Resume play.  This can only be called after a pause.
  240.  */
  241. void ResumeSelection()
  242. {
  243.   if (playerState == PauseMode)                        /* Make doubly sure that the player is in PauseMode.  If not, do not play, */
  244.   {                                    /* since play will then start from the beginning of the CD. */
  245.     Play(NULL, NULL);
  246.   }
  247. }
  248.  
  249. /*
  250.  * Iconify the application.
  251.  */
  252. void HideApplication()
  253. {
  254.   xv_set(cdEdit_window1->window1, FRAME_CLOSED, TRUE, NULL);        /* Iconify the app */
  255. }
  256.  
  257. /*
  258.  * Bring to the front the application, including all its popup windows.
  259.  */
  260. void ShowApplication()
  261. {
  262.   xv_set(cdEdit_window1->window1, FRAME_CLOSED, FALSE, NULL);        /* Open the app if it is iconified */
  263.   xv_set(cdEdit_window1->window1, XV_SHOW, TRUE, NULL);            /* Bring the app to the front */
  264.   if (xv_get(cdEdit_EditPopup->EditPopup, XV_SHOW) == TRUE) 
  265.   {
  266.     xv_set(cdEdit_EditPopup->EditPopup, XV_SHOW, TRUE, NULL);
  267.   }
  268.   if (xv_get(cdEdit_PreviewPopup->PreviewPopup, XV_SHOW) == TRUE) 
  269.   {
  270.     xv_set(cdEdit_PreviewPopup->PreviewPopup, XV_SHOW, TRUE, NULL);
  271.   }
  272. }
  273.  
  274. /* 
  275.  * This application will return the icon bits to the requesting application.
  276.  */
  277. IconData* GetAppIcon()
  278. {
  279.   static IconData returnVal;
  280.   static unsigned short iconBits[] = 
  281.   {
  282. #include "icons/cdEditIcon"
  283.   };
  284.  
  285.   returnVal.iconData = (char *) malloc(sizeof(iconBits));
  286.   bcopy(iconBits, returnVal.iconData, sizeof(iconBits));
  287.   if (returnVal.iconData) 
  288.   {
  289.     returnVal.dataLength = sizeof(iconBits);
  290.   }
  291.   return(&returnVal);
  292. }
  293.  
  294.  
  295.